home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Devices / CD-ROM / iso9660 / Srcs / mydialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-28  |  4.6 KB  |  212 lines  |  [TEXT/MPS ]

  1. /************************************************************************
  2.  *
  3.  *    Copyright © 1990    Apple Computer, Inc.  All rights reserved.
  4.  *
  5.  ************************************************************************/
  6.  
  7. #include <stdio.h>
  8. #include <strings.h>
  9. #include <Dialogs.h>
  10. #include <Windows.h>
  11. #include <Fonts.h>
  12. #include <Files.h>
  13. #include <Resources.h>
  14. #include <Memory.h>
  15.  
  16. #include "mydialog.h"
  17. #include "textdlog.h"
  18. #include "DialogUtils.h"
  19. #include "mydialog.proto.h"
  20.  
  21. #define    VOLNAME_DIALOG        256
  22. #define    DESTROY_DIALOG        257
  23. #define FirstButton            1
  24. #define SecondButton        2
  25. #define StringField            3
  26.  
  27. static void strcpy255(char *dst, char *src);
  28.  
  29. extern void strcpy255(char *, char *);
  30.  
  31.  
  32. /************************************************************************
  33.  *
  34.  *  Function:        strcpy255
  35.  *
  36.  *  Purpose:        copy a string
  37.  *
  38.  *  Returns:        nothing
  39.  *
  40.  *  Side Effects:    copies *src into *dst
  41.  *
  42.  *  Description:    loop copying until we hit the null byte of src.
  43.  *                    We stop copying if we try to copy more than 255
  44.  *                    chars at a time.
  45.  *
  46.  ************************************************************************/
  47. static void
  48. strcpy255(char *dst, char *src)
  49. {
  50.     short i = 0;
  51.     while ( ( (*dst++ = *src++) != 0) & (i++ < 255) )
  52.         /* nothing */ ;
  53. }
  54.  
  55. /************************************************************************
  56.  *
  57.  *  Function:        AskForString
  58.  *
  59.  *  Purpose:        ask the user for a string.
  60.  *
  61.  *  Returns:        Boolean
  62.  *                        true if the user entered something
  63.  *                        false if the user asked to cancel out
  64.  *
  65.  *  Side Effects:
  66.  *                    theString is filled with a C string if we return true.
  67.  *
  68.  *  Description:
  69.  *                    put up a dialog.
  70.  *
  71.  ************************************************************************/
  72. Boolean
  73. AskForString(char *prompt, char *theString)
  74. {
  75.     DialogPtr        dPtr;
  76.     short            result;
  77.     
  78.     short            unusedType;    /* for hiliting okay button */
  79.     Handle            hItem;
  80.     Rect            dBox;
  81.     
  82.     Boolean            leaveYet;
  83.     
  84.     Str255            enteredString;
  85.  
  86.     dPtr = GetNewDialog(DU_CenterDLOG(VOLNAME_DIALOG), (DialogPeek)0L, (WindowPtr)-1);
  87.     
  88.     HighLightDefault(dPtr);                /* hilite OK button */
  89.     
  90.     SelIText(dPtr, StringField, 0, 999); /* all of the string field selected */
  91.  
  92.     ParamText((StringPtr)prompt, NULL, NULL, NULL);
  93.     
  94.     leaveYet = false;
  95.     do
  96.     {
  97.         HighLightDefault(dPtr);
  98.         ModalDialog(0, &result);
  99.         if (result == FirstButton) 
  100.             leaveYet = true;
  101.         if (result == SecondButton)
  102.         {
  103.             SysBeep(1);
  104.             leaveYet = true;
  105.             return false;
  106.         }
  107.     } while (leaveYet == false);
  108.     
  109.  
  110.     GetDItem(dPtr, StringField, &unusedType, &hItem, &dBox);
  111.     GetIText(hItem, (StringPtr)&enteredString);
  112.     strcpy255(theString, P2CStr((StringPtr)&enteredString));
  113.     DisposDialog(dPtr);
  114.     return true;
  115. }
  116.  
  117. /************************************************************************
  118.  *
  119.  *  Function:        AskDestroyDisk
  120.  *
  121.  *  Purpose:        Check that you really want to nuke a disk
  122.  *
  123.  *  Returns:        Boolean
  124.  *                    true = yes, destroy it
  125.  *                    false = no, leave it alone, it was a mistake.
  126.  *
  127.  *  Side Effects:    none.
  128.  *
  129.  *  Description:    display our warning about destroying a disk.
  130.  *                    Ask, using a modal dialog, whether the user really
  131.  *                    wants to lose it.  (Default button is cancel, since
  132.  *                    this is such a permanent thing...)
  133.  *
  134.  *
  135.  ************************************************************************/
  136. Boolean
  137. AskDestroyDisk(short gDriveNumber)
  138. {
  139.     DialogPtr        dPtr;
  140.     short            result;
  141.     Boolean            leaveYet;
  142.     Boolean            okayToDestroy;
  143.     
  144.     Str255            volumeName;
  145.     short            vRefNum;
  146.     long            freeBytes;
  147.  
  148.     okayToDestroy = true;
  149.     dPtr = GetNewDialog(DU_CenterDLOG(DESTROY_DIALOG), (DialogPeek)0L, (WindowPtr)-1);
  150.  
  151.     HighLightDefault(dPtr);
  152.     
  153.     if (GetVInfo(gDriveNumber, volumeName, &vRefNum, &freeBytes) != noErr)
  154.         okayToDestroy = false;
  155.     
  156.     if (okayToDestroy)
  157.     {
  158.         ParamText((StringPtr)volumeName, NULL, NULL, NULL);
  159.         
  160.         leaveYet = false;
  161.         do
  162.         {
  163.             HighLightDefault(dPtr);
  164.             ModalDialog(0, &result);
  165.             if (result == SecondButton) 
  166.                 leaveYet = true;
  167.             if (result == FirstButton)
  168.             {
  169.                 SysBeep(1);
  170.                 leaveYet = true;
  171.                 okayToDestroy = false;
  172.             }
  173.         } while (leaveYet == false);
  174.     }
  175.  
  176.     DisposDialog(dPtr);
  177.     return okayToDestroy;
  178. }
  179.  
  180.  
  181.  
  182. /************************************************************************
  183.  *
  184.  *  Function:        Help
  185.  *
  186.  *  Purpose:        explain what we're doing
  187.  *
  188.  *  Returns:        void
  189.  *
  190.  *  Side Effects:    none.
  191.  *
  192.  *  Description:    display our help text.  Currently always returns true.
  193.  *
  194.  *
  195.  ************************************************************************/
  196. Boolean
  197. Help(void)
  198. {
  199.     Handle    tHandle;
  200.         
  201.     tHandle = GetResource('TEXT', 1001);
  202.     if (tHandle != (Handle)0)
  203.     {
  204.         HLock(tHandle);
  205.         TextDialog(1001, tHandle, times, 12, true);
  206.         HUnlock(tHandle);
  207.         ReleaseResource(tHandle);
  208.     }
  209.     return true;
  210. }
  211.  
  212.